<?php

namespace app\common\model;

use think\Model;

class Withdraw extends Model
{
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'type_text',
        'status_text'
    ];
    
    // 提现方式
    public static $typeList = [
        'wechat' => '微信',
        'alipay' => '支付宝'
    ];
    
    // 状态
    public static $statusList = [
        'created' => '待审核',
        'approved' => '已通过',
        'rejected' => '已驳回',
        'completed' => '已打款',
        'wait_user_confirm' => '用户确认中',
        'processing'=>'转账处理中',
        'closed'=>'转账关闭',
        'failed'=>'转账失败',
        'unknown'=>'未知状态'
    ];
    
    public function getTypeTextAttr($value, $data)
    {
        return isset($data['type']) ? self::$typeList[$data['type']] : '';
    }
    
    public function getStatusTextAttr($value, $data)
    {
        return isset($data['status']) ? self::$statusList[$data['status']] : '';
    }
    
    // 定义用户关联
    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}